<template>
  <div class="tab-control" :style='{background:bgColor}'>
    <div class="tab-control-item" :class='{active: index === currentIndex}' @click='changeIndex(index)' v-for="(item, index) in title" :key='index'>
      <span>{{ item }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "TabControl",
  props: {
    title: {
      type: Array,
      default(){
        return []
      }
    },
    bgColor: {
      type: String,
      default: '#fff'
    }
  },
  data(){
      return {
        currentIndex: 0
      }
    },
    methods: {
      changeIndex(index){
        if(this.currentIndex == index) return;
        this.currentIndex = index
        this.$emit('tabClick',index)
      }
    }
}
</script>

<style scoped>
  .tab-control {
    display: flex;
    height: 40px;
    line-height: 40px;
  }
  .tab-control-item {
    flex: 1;
    text-align: center;
  }
  .tab-control-item span {
    padding: 5px;
  }
  .active span{
    color: var(--color-high-text);
    border-bottom: 3px solid var(--color-tint)
  }
</style>